<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./font/iconfont.css">
<style>
*{
    margin: 0;
    padding: 0;
    list-style: none;
}
body{
    height: 2000px;
}
.nav{
    position: fixed;
    right: 0;
    top: 220px;
    width: 50px;
}
.nav li{
    width: 50px;
    height: 50px;
    position: relative;
    margin: 5px 0;
    cursor: pointer;
}
.nav li h3{
    font-size: 24px;
    color: #fff;
    background-color: #999;
    width: 50px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-weight: normal;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 10;
}
.nav li p{
    position: absolute;
    left: 0;
    top: 0;
    width: 80px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    background-color: #999;
    color: #fff;
    font-size: 18px;
    z-index: 5;
}
</style>
</head>
<body>
    
<ul class="nav">
    <li>
        <h3 class="iconfont icondianzan2"></h3>
        <p>点赞</p>
    </li>
    <li>
        <h3 class="iconfont iconguanzhu"></h3>
        <p>关注</p>
    </li>
    <li>
        <h3 class="iconfont iconstar2"></h3>
        <p>收藏</p>
    </li>
    <li>
        <h3 class="iconfont iconup"></h3>
        <p class="totop">返顶</p>
    </li>
</ul>

<script src="./utils.js"></script>
<script>
// 获取元素
var lis = $('.nav li');
var totop = $('.totop');

// 给每一个li添加事件
for (var i = 0; i < lis.length; i++) {
    lis[i].onmouseenter = function (){
        // this -> 鼠标进入的那个li
        // 修改元素的背景颜色
        this.firstElementChild.style.backgroundColor = 'pink';
        this.lastElementChild.style.backgroundColor = 'pink';
        // p标签向左运动
        animate(this.lastElementChild,'left',-80);
    }
    lis[i].onmouseleave = function (){
        // this -> 鼠标进入的那个li
        // 修改元素的背景颜色
        this.firstElementChild.style.backgroundColor = '#999';
        this.lastElementChild.style.backgroundColor = '#999';
        // p标签向左运动
        animate(this.lastElementChild,'left',0);
    }
}

totop.onclick = function (){
    animate(document.documentElement,'scrollTop',0);
}

</script>
</body>
</html>